home *** CD-ROM | disk | FTP | other *** search
- package asp.wizard;
-
- import asp.netobjects.nfx.util.ExceptionHandler;
- import asp.netobjects.nfx.util.ExternalError;
- import asp.netobjects.nfx.util.InternalError;
- import asp.netobjects.nfx.wizard.Wizard;
- import asp.netobjects.nfx.wizard.WizardPage;
- import asp.netobjects.nfx.wizard.WizardPageView;
- import asp.util.ResourceUtil;
- import asp.wizard.def.DefConnection;
- import com.sun.java.swing.ImageIcon;
- import java.sql.Connection;
-
- public class WizardModelDbConnection extends WizardModelAbstract {
- private DefConnection _defConnection;
- private boolean _defExists = false;
- public static final String ERR_DS_INVALID = "error.ds_invalid";
- public static final String ERR_DSTYPE_INVALID = "error.dstype_invalid";
- public static final String ERR_CONN_INVALID_REQD = "error.conn_invalid_reqd";
- public static final String ERR_CONN_VALID = "msg.conn_valid";
- public static final String ERR_CONN_INVALID = "error.conn_invalid";
- // $FF: synthetic field
- static Class class$asp$wizard$WVPanelDbConnection;
-
- public void commit() throws InternalError, ExternalError {
- WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
- if (this._defConnection == null) {
- this._defConnection = new DefConnection();
- String name = ((WizardModelAbstract)this).getDefPage().getUniqueNameFor(this._defConnection);
- this._defConnection.setName(name);
- ((WizardModelAbstract)this).getDefPage().addElement(this._defConnection);
- }
-
- this._defConnection.setOdbcType(view.getOdbcType());
- this._defConnection.setDSNName(view.getDSNName());
- this._defConnection.setUserName(view.getUserName());
- this._defConnection.setPassword(view.getPassword());
- this._defConnection.setGlobalConnection(view.getGlobalConnection());
- }
-
- public void loadValues() {
- WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
- if (this._defConnection == null) {
- view.setDSNName("");
- view.setUserName("");
- view.setPassword("");
- view.setGlobalConnection(view.getGlobalConnection());
- } else {
- view.setDSNName(this._defConnection.getDSNName());
- view.setUserName(this._defConnection.getUserName());
- view.setPassword(this._defConnection.getPassword());
- view.setGlobalConnection(this._defConnection.getGlobalConnection());
- }
-
- }
-
- public void loadView() {
- WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
- view.updateDataSources();
- this.loadValues();
- }
-
- public void validate() throws InternalError, ExternalError {
- super.validate();
- WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
- if (view != null && !view.getDSNName().equals("")) {
- if (view.getOdbcType() == -1) {
- String err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "error.dstype_invalid");
- throw new ExternalError(err);
- } else {
- try {
- Connection _conn = this.getConnection();
- } catch (EWizDbManager e) {
- String err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "error.conn_invalid_reqd");
- throw new ExternalError(err + " " + ((Throwable)e).getMessage());
- }
- }
- } else {
- String err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "error.ds_invalid");
- throw new ExternalError(err);
- }
- }
-
- public Connection getConnection() throws EWizDbManager {
- WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
- Connection myConn = null;
-
- try {
- WizDbManager WDBM = WizDbManager.getInstance();
- myConn = WDBM.getConnection(view.getDSNName(), view.getUserName(), view.getPassword());
- return myConn;
- } catch (EWizDbManager e) {
- throw new EWizDbManager(((Throwable)e).getMessage());
- }
- }
-
- public void testConnection() {
- String err = null;
-
- try {
- this.getConnection();
- err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "msg.conn_valid");
- AspWizardExceptionHandler.showMessage(1, err);
- } catch (EWizDbManager e) {
- err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "error.conn_invalid");
- AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
- }
-
- }
-
- public WizardModelDbConnection() {
- }
-
- public WizardModelDbConnection(Wizard wizard, String bullet, String info, ImageIcon icon, ExceptionHandler handler) {
- super(wizard, bullet, info, icon, handler);
- }
-
- protected WizardPageView getViewSingleInstance() {
- return WizardViewDbConnection.getInstance();
- }
-
- public DefConnection getDefConnection() {
- return this._defConnection;
- }
-
- public void setDefConnection(DefConnection dc) {
- this._defConnection = dc;
- }
-
- // $FF: synthetic method
- static Class class$(String class$) {
- try {
- return Class.forName(class$);
- } catch (ClassNotFoundException forName) {
- throw new NoClassDefFoundError(((Throwable)forName).getMessage());
- }
- }
- }
-